package com.macro.mall.controller;

import com.github.pagehelper.PageInfo;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.e.SysWebEntDTO;
import com.macro.mall.dto.o.SysWebOutDTO;
import com.macro.mall.service.SysWebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys/web")
public class SysWebController {

    @Autowired
    private SysWebService sysWebService;

    @RequestMapping("/list")
    public CommonResult list(@RequestBody SysWebEntDTO sysWebEntDTO){
        PageInfo<SysWebOutDTO> list = sysWebService.list(sysWebEntDTO);
        return CommonResult.success(list);
    }

    @RequestMapping("/get")
    public CommonResult get(@RequestBody SysWebEntDTO sysWebEntDTO){
        return null;
    }

    @RequestMapping("/modify")
    public CommonResult modify(@RequestBody SysWebEntDTO sysWebEntDTO){
        int modify = sysWebService.modify(sysWebEntDTO);
        CommonResult<Object> commonResult = new CommonResult<>();
        if (modify>0){
            commonResult.setCode(200);
            commonResult.setMessage("操作成功！");
        }else {
            commonResult.setCode(500);
            commonResult.setMessage("操作失败！");
        }
        return commonResult;
    }

    @RequestMapping("/setStatus")
    public CommonResult setOn(@RequestBody SysWebEntDTO sysWebEntDTO){
        int modify = sysWebService.modify(sysWebEntDTO);
        CommonResult<Object> commonResult = new CommonResult<>();
        if (modify>0){
            commonResult.setCode(200);
            commonResult.setMessage("操作成功！");
        }else {
            commonResult.setCode(500);
            commonResult.setMessage("操作失败！");
        }
        return commonResult;
    }

    @RequestMapping("/setOff")
    public CommonResult setOff(@RequestBody SysWebEntDTO sysWebEntDTO){
        return null;
    }
}
